package org.agilelang.generator.cakephp;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.File;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.agilelang.plugin.IPlugin;

public class Plugin implements IPlugin {

    String PathXml = "";
    String driver = "", user = "", passwod = "", port = "";

    @Override
    public String getNamePlugin() {
        return "Agile Engine PHP";
    }

    @Override
    public String getVersionPlugin() {
        return "v1.3.1";
    }

    @Override
    public String getDescriptionPlugin() {
        return "Autor : Roderick Cusirramos Montesinos \n"
                + "Fecha : 02/12/2012 \n"
                + "Lenguaje de Programacion : PHP \n"
                + "Base de Datos : MySql \n"
                + "Descripcion : Generador de codigo para el framework CakePHP";
    }

    @Override
    public String getMenu() {
        return "generator";
    }

    @Override
    public String getMenuTitle() {
        return "Sincronizador";
    }

    @Override
    public void setPathXml(String path) {
        PathXml = path;
    }

    @Override
    public String getDBs() {
        return "MySql";
    }

    @Override
    public void setDB(String driver, String user, String passwod, String port) {
        this.driver = driver;
        this.user = user;
        this.passwod = passwod;
        this.port = port;
    }

    @Override
    public void processPlugin() {
        if (PathXml.equals("")) {
            JOptionPane.showMessageDialog(new JFrame(),
                    "Path is blank",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (!(new File(PathXml)).exists()) {
            JOptionPane.showMessageDialog(new JFrame(),
                    "File xml not exists",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        DlgGenerateCakePHP dlg = new DlgGenerateCakePHP();
        dlg.setLocationRelativeTo(null);
        dlg.setVisible(true);
        if (dlg.isStatus()) {
            ICakePHP test = new ICakePHP(PathXml, dlg.getPath());
            test.setTemplate("bootstrap");
            test.processFile();
            test.processController();
            test.processModel();
            test.processMenu();
        }
    }
}
